﻿using CKS.AGV.Core.Enum;
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntdUI;
namespace CKS.AGV.Server.ViewModel
{
    public class View_convey_tasks : AntdUI.NotifyProperty
    {
        private AgvTaskStatus taskStatus;
        private bool matchOut;
        private AgvStatus lastAgvReqStatus;
        private ResAgvStatus lastAgvRspStatus;
        private string sendHex = string.Empty;
        private DateTime endTime;


        public View_convey_tasks()
        {

        }


        AntdUI.CellLink[] _Operate;
        [Column(IsIgnore =true)]
        public AntdUI.CellLink[] Operate
        {
            get
            {
                if((int)this.TaskStatus >5 )
                    return null;
                _Operate = new AntdUI.CellLink[] {
                         
                        new AntdUI.CellButton("cancel", "取消任务",AntdUI.TTypeMini.Error)
                    };
                return _Operate;
            }
            set
            {
                _Operate = value;
                OnPropertyChanged("Operate");
            }
        }
        /// <summary>
        /// 任务编号
        /// </summary>
        [Column(IsIdentity = true, IsPrimary = true)]
        public long Id { get; set; }
        /// <summary>
        /// 任务描述
        /// </summary>
        public string Desc { get; set; }

        /// <summary>
        /// 海康任务编号
        /// </summary>
        public string HikTaskCode { get; set; }=string.Empty;
        /// <summary>
        /// 任务类型：1 呼叫送料 2呼叫取料
        /// </summary>
        public int TaskType { get; set; }
        /// <summary>
        /// 是否手动测试，仅测试输送坐标
        /// </summary>
        public bool IsTest { get; set; }
        /// <summary>
        /// 零件类型
        /// </summary>
        public int PartType { get; set; }
        /// <summary>
        /// 路径起点
        /// </summary>
        public int StartPathPoint { get; set; }
        /// <summary>
        /// 路径终点
        /// </summary>
        public int EndPathPoint { get; set; }

        /// <summary>
        /// 起点请求信号
        /// </summary>
        public int StartReqSignalAddr { get; set; }
        /// <summary>
        /// 起点响应信号
        /// </summary>
        public int StartRspSignalAddr { get; set; }
        /// <summary>
        /// 终点请求信号
        /// </summary>
        public int EndReqSignalAddr { get; set; }
        /// <summary>
        /// 终点响应
        /// </summary>
        public int EndRspSignalAddr { get; set; }

        public int StartPlcId { get; set; }

        public int EndPlcId { get; set; }

        /// <summary>
        /// 匹配出料成功
        /// </summary>
        public bool MatchOut { get => matchOut; set
            {
                matchOut = value;
                OnPropertyChanged("MatchOut");

            }
        }
        /// <summary>
        /// 任务状态
        /// </summary>
        [Column(MapType = typeof(int))]
        public AgvTaskStatus TaskStatus
        {
            get => taskStatus;
            set
            {
                taskStatus = value;
                OnPropertyChanged("TaskStatus");
                OnPropertyChanged("Operate");

            }
        }
        /// <summary>
        /// AGV请求状态
        /// </summary>
        [Column(MapType = typeof(int))]
        public AgvStatus LastAgvReqStatus { get => lastAgvReqStatus;
            set
            {
                lastAgvReqStatus = value;
                OnPropertyChanged("LastAgvReqStatus");

            }
        }

        /// <summary>
        /// 反馈AGV状态
        /// </summary>
        [Column(MapType = typeof(int))]
        public ResAgvStatus LastAgvRspStatus { 
            get => lastAgvRspStatus; set
            {
                lastAgvRspStatus = value;
                OnPropertyChanged("LastAgvRspStatus");

            }
        }

        /// <summary>
        /// 下发任务时的二进制
        /// </summary>
        public string SendHex { get => sendHex; set
            {
                sendHex = value;
                OnPropertyChanged("SendHex");

            }
        }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndTime { get => endTime; set
            {
                endTime = value;
                OnPropertyChanged("EndTime");

            }
        }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 发送任务给AGV的时间
        /// </summary>
        public DateTime? SendTime { get; set; }
    }
}
